package com.service.impl;

import com.mapper.GroupCommentImgMapper;
import com.pojo.GroupCommentImg;
import com.pojo.GroupCommentImgExample;
import com.service.GroupCommentImgService;
import com.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2020/3/19 0019.
 */
@Service
public class GroupCommentImgServiceImpl implements GroupCommentImgService {

    @Autowired
    GroupCommentImgMapper groupCommentImgMapper;

    @Override
    public ServerResponse save(GroupCommentImg img) {
        Byte status =1;
        img.setStatus(status);
        //执行mybatis添加方法
        int rows = groupCommentImgMapper.insert(img);
        //判断添加成功
        if (rows > 0)
            return ServerResponse.addSuccess();
        else
            return ServerResponse.addFailed();
    }

    @Override
    public ServerResponse modifyStatus(Integer id) {
        GroupCommentImg img = groupCommentImgMapper.selectByPrimaryKey(id);
        Byte status = 0;
        img.setStatus(status);
        int i = groupCommentImgMapper.updateByPrimaryKeySelective(img);
        if (i>0)
            return ServerResponse.deleteSuccess();
        return ServerResponse.deleteFailed();
    }

    @Override
    public ServerResponse modify(GroupCommentImg img) {
        int i = groupCommentImgMapper.updateByPrimaryKeySelective(img);
        if (i>0)
            return ServerResponse.updateSuccess();
        return ServerResponse.updateFailed();
    }

    @Override
    public ServerResponse getById(Integer id) {
        GroupCommentImg user = groupCommentImgMapper.selectByPrimaryKey(id);
        return ServerResponse.getDataSuccess(user);
    }

    @Override
    public ServerResponse getAll() {
        GroupCommentImgExample example=new GroupCommentImgExample();
        GroupCommentImgExample.Criteria criteria = example.createCriteria();
        Byte status = 1;
        criteria.andStatusEqualTo(status);
        List<GroupCommentImg> imgs= groupCommentImgMapper.selectByExample(example);
        if (imgs!=null&&imgs.size()>0)
            return ServerResponse.getDataSuccess(imgs);
        return ServerResponse.getDataFailed("没有数据");
    }

    @Override
    public ServerResponse getByCommentID(String commentId) {
        GroupCommentImgExample example=new GroupCommentImgExample();
        GroupCommentImgExample.Criteria criteria = example.createCriteria();
        Byte status = 1;
        criteria.andStatusEqualTo(status);
        criteria.andCommIdEqualTo(Integer.valueOf(commentId));
        List<GroupCommentImg> imgs= groupCommentImgMapper.selectByExample(example);
        if (imgs!=null&&imgs.size()>0)
            return ServerResponse.getDataSuccess(imgs);
        return ServerResponse.getDataFailed("没有数据");
    }
}
